// 页面路径：store/index.js 
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex); //vue的插件机制

//Vuex.Store 构造器选项
const store = new Vuex.Store({
	state: { //存放状态
		//计划
		planDetails: [{
			"cycle": 2,
			"hobby": [
				0,
				3
			],
			"zhou": "亚洲",
			"country": "泰国",
			"city": "海口",
			"money": 1000,
			"startDate": "2022-05-26",
			"startCity": "三亚"
		}, {
			"cycle": 2,
			"hobby": [
				0,
				3
			],
			"zhou": "亚洲",
			"country": "泰国",
			"city": "海口",
			"money": 1000,
			"startDate": "2022-05-26",
			"startCity": "三亚"
		}, {
			"cycle": 2,
			"hobby": [
				0,
				3
			],
			"zhou": "亚洲",
			"country": "泰国",
			"city": "海口",
			"money": 1000,
			"startDate": "2022-05-26",
			"startCity": "三亚"
		}],
		forcedLogin: false, //是否需要强制登录
		hasLogin: false, // 未登录状态
		userName: "",
		userPassword: "",
		collectionMsg: [] // 收藏信息
	},
	mutations: {
		commitPlan(state, data) { // 新增计划列表
			state.planDetails.push(data)
		},
		delPlan(state, index) { // 删除计划
			state.planDetails.splice(index, 1);
		},
		// 登录的方法
		login(state, user) {
			state.userName = user.userName || "";
			state.hasLogin = true;
			state.userPassword = user.password || "";
			uni.setStorage({
				key: "userInfo",
				data: user,
			})
		},
		// 退出登录的方法
		logout(state) {
			state.userName = "";
			state.hasLogin = false;
			state.userPassword = "";
			state.token = "";
			state.pointId = "";
			uni.removeStorage({
				key: "userInfo",
			})
		},
		// 收藏的方法
		collectionMsg(state, data) {
			state.collectionMsg.push(data)
		},
		// 取消收藏的方法
		delCollectionMsg(state, index) {
			state.collectionMsg.splice(index, 1);
		}
	}
})

export default store
